package m202405.d28;

import java.util.PriorityQueue;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/28 17:24
 */
public class Q215 {

    public static void main(String[] args) {
        Q215 q215 = new Q215();
        int kthLargest = q215.findKthLargest(new int[]{3,2,1,5,6,4}, 2);
        System.out.println(kthLargest);
    }

    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int num : nums) {
            queue.add(num);
            if (queue.size() > k) {
                queue.remove();
            }
        }
        return queue.remove();
    }
}
